package me.jessyan.mvparms.demo.di.module.user;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.widget.CustomPopupWindow;

import java.util.Date;

import javax.inject.Named;

import dagger.Module;
import dagger.Provides;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.contract.user.PersonalDataContract;
import me.jessyan.mvparms.demo.mvp.model.user.PersonalDataModel;
import me.jessyan.mvparms.demo.utils.PerfectClickListener;


@Module
public class PersonalDataModule {
    private PersonalDataContract.View view;

    /**
     * 构建PersonalDataModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public PersonalDataModule(PersonalDataContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    PersonalDataContract.View providePersonalDataView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    PersonalDataContract.Model providePersonalDataModel(PersonalDataModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    @Named("sexPop")
    CustomPopupWindow sexPop(){
        //选择优惠券
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_sex,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .isWithMatch(true)
                .contentView(content)
                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                        contentView.findViewById(R.id.man_tv).setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popBackSex("男");
                            }
                        });
                        contentView.findViewById(R.id.woman_tv).setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popBackSex("女");
                            }
                        });
                        contentView.findViewById(R.id.cancel_tv).setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popDismiss();
                            }
                        });
                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        return popupWindow;
    }

    @ActivityScope
    @Provides
    @Named("choicePicPop")
    CustomPopupWindow choicePicPop(){
        //选择优惠券
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_sex,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .isWithMatch(true)
                .contentView(content)
                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                        TextView titleTv= contentView.findViewById(R.id.title_tv);
                        titleTv.setText("修改头像");
                        TextView manTv = contentView.findViewById(R.id.man_tv);
                        manTv.setText("拍照");
                        TextView womanTv= contentView.findViewById(R.id.woman_tv);
                        womanTv.setText("相册选择");


                       manTv.setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popBackChoicePic(1);
                            }
                        });
                        womanTv.setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popBackChoicePic(2);
                            }
                        });
                        contentView.findViewById(R.id.cancel_tv).setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.popDismiss();
                            }
                        });
                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        return popupWindow;
    }

    @ActivityScope
    @Provides
    TimePickerView provideTimer(){
        //时间选择器
        TimePickerBuilder timePickerBuilder = new TimePickerBuilder(view.getActivity(), new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                view.timerBackBirth(date);
            }
        }).setLayoutRes(R.layout.pop_custom_picker_time, new CustomListener() {
            @Override
            public void customLayout(View v) {
                //自定义布局中的控件初始化及事件处理
                final TextView tvSubmit = (TextView) v.findViewById(R.id.btnSubmit);
                final TextView tvCancel = (TextView) v.findViewById(R.id.btnCancel);

                tvSubmit.setOnClickListener(new PerfectClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {

                    view.popTimeBackSuccss();

                    }
                });
                tvCancel.setOnClickListener(new PerfectClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {
                        view.popDismiss();
                    }
                });


            }
        });
        TimePickerView pvTime = timePickerBuilder.build();
        return pvTime;
    }


}